package com.ruoyi.web.controller.project;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.Task;
import com.ruoyi.system.service.ITaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/project/task")
public class TaskController {
    @Autowired
    private ITaskService taskService;

    @GetMapping("/{taskId}")
    public AjaxResult getTask(@PathVariable int taskId) {
        Task task = taskService.selectTaskById(taskId);
        return AjaxResult.success(task);
    }

    @GetMapping("/list")
    public AjaxResult listTasks(Task task) {
        List<Task> list = taskService.selectTaskList(task);
        return AjaxResult.success(list);
    }

    @PostMapping("/add")
    public AjaxResult addTask(@RequestBody Task task) {
        int result = taskService.insertTask(task);
        return result > 0 ? AjaxResult.success() : AjaxResult.error();
    }

    @PostMapping("/update")
    public AjaxResult updateTask(@RequestBody Task task) {
        int result = taskService.updateTask(task);
        return result > 0 ? AjaxResult.success() : AjaxResult.error();
    }
} 